package com.cold.demo.template.controller;

import com.cold.demo.template.pojo.Chunk;
import com.cold.demo.template.service.BigFileServiceInterface;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 李建 2020年5月19日17:05:57
 * 文件Controller
 * 处理文件的上传与下载
 * 使用了 《vue-simple-uploader》 这个组件
 */
@RestController
@RequestMapping("/bigFile")
public class BigFileController {

    final BigFileServiceInterface bigFileServiceInterface;

    public BigFileController(BigFileServiceInterface bigFileServiceInterface) {
        this.bigFileServiceInterface = bigFileServiceInterface;
    }

    /**
     * 处理文件上传POST请求
     * 将上传的文件存放到服务器内
     *
     * @param chunk    文件块
     * @param response 响应
     * @return 上传响应状态
     */
    @PostMapping("/fileUpload")
    public String uploadPost(@ModelAttribute Chunk chunk, HttpServletRequest request, HttpServletResponse response) {
        return bigFileServiceInterface.fileUploadPost(chunk, response);
    }


}
